import { Table } from "antd";
import styles from "./index.less";
import { useMemo } from "react";
import { isEmpty } from "@/utils";
import TableFooter from "./TableFooter";
export default ({
  top = null,
  columns = [],
  setting,
  hasIndex = true,
  ...restProps
}) => {
  const tableColumns = useMemo(() => {
    //加序号
    const arr = hasIndex
      ? [
          {
            title: "序号",
            // align: "center",
            dataIndex: "index",
            render: (v, item, index) => (
              <>{index + 1 + (setting?.current - 1) * setting?.pageSize}</>
            ),
          },
          ...columns,
        ]
      : columns;
    return arr.map((item) => {
      //空值时显示'-'
      return {
        ...item,
        render: item?.render ?? ((t) => (isEmpty(t) ? "--" : t)),
      };
    });
  }, []);
  return (
    <div className={styles.container}>
      {top && <div className={styles.tableTop}>{top}</div>}
      <Table
        footer={
          setting
            ? () => (
                <TableFooter
                  setting={setting}
                  // customTotal={customTotal}
                  // customPagination={customPagination}
                />
              )
            : null
        }
        rowKey={"id"}
        columns={tableColumns}
        className={styles.table}
        {...restProps}
        pagination={false}

      />
    </div>
  );
};
